
    <title>欠款核销</title>
    <style type="text/css">
        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }
    </style>
<div class="layui-fluid" style="padding: 15px">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header" style="height: 130px;padding-top: 10px;">
                    <form class="layui-form layui-form-pane" action="#" lay-filter="example">
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">托运日期：</label>
                                <div class="layui-inline">
                                    <input name="consignDate"  id="consignDate" class="layui-input" type="date" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">业务员：</label>
                                <div class="layui-inline">
                                    <input name="tms_name" id="tms_name" class="layui-input"  autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">欠款单位：</label>
                                <div class="layui-inline">
                                    <input name="forwardingUnit" id="forwardingUnit" class="layui-input"  autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">发生站点：</label>
                                <div class="layui-inline">
                                    <select id="substationUnit" name="sub_id">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">核销状态：</label>
                                <div class="layui-inline">
                                    <select name="verification" id="verification">
                                        <option value="">请选择</option>
                                        <option value="false">false</option>
                                        <option value="true">true</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body">
                    <table id="consigner" lay-filter="consignerTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarMenu">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" type="button" lay-event="sousuo">查询</button>
        <button class="layui-btn layui-btn-sm" lay-event="addMenutble">派送核销</button>
        <button class="layui-btn layui-btn-sm" lay-event="zuofei">欠款作废</button>
    </div>
</script>
<script>
    layui.use(['form','jquery','table'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;


        //进入就发送请求
        $.ajax({
            url: "../../getAllSubstation",
            type: "post",
            data: {},
            dataType: "json",
            success: function (data) {
                //动态添加下拉框
                for (var i = 0; i < data.length; i++) {
                    $("#substationUnit").append("<option value='" + data[i].subId + "'>" + data[i].subName + "</option>");
                }
                //刷新
                form.render('select');
            }
        })




        //菜单表格
        table.render({
            elem: '#consigner'
            ,height: 500
            ,id:'consignerTable'
            ,url: '../../DebtControllerGetALLDebt' //数据接口
            ,toolbar: '#toolbarMenu' //开启头部工具栏，并为其绑定左侧模板
            ,limit:8
            ,limits:[8,16,24,32]
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_menu'
                ,icon: 'layui-icon-tips'
            }]
            ,page: true //开启分页
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'finance',width:180, title: '财务单号'}
                ,{field: 'consignDate',width:180,title: '欠款日期'}
                ,{field: 'orderStatus', width:120,title: '欠款状态'}
                ,{field: 'oweFee',width:180, title: '应收金额'}
                ,{field: 'forwardingUnit',width:220, title: '欠款单位'}
                ,{field: 'clientName', width:180,title: '欠款人'}
                ,{field: 'phone',width:120, title: '电话号码'}
                ,{field: 'tms_name', width:180,title: '业务员'}
                ,{field: 'remark',width:180, title: '备注'}
                ,{field: 'sub_name',width:180, title: '分站名称'}
                ,{field: 'verification',width:120, title: '核销状态',}
            ]]
        })


        //角色头部工具栏头工具栏事件
        table.on('toolbar(consignerTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch(obj.event) {
                case 'sousuo':
                    //执行重载
                    table.reload('consignerTable', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        //根据条件查询
                        ,where: {
                            consignDate:$("#consignDate").val(),
                            tms_name:$("#tms_name").val(),
                            forwardingUnit:$("#forwardingUnit").val(),
                            sub_id:$('#substationUnit option:selected').val(),
                            verification:$('#verification option:selected').val()
                        }
                    });
                    return false;
                    break;
                case 'addMenutble':
                    if (data.length==0){
                        alert("请选择一行")
                    } else if (data.length>1){
                        alert("只能选中一行")
                    }else {
                        $.ajax({
                            url: "../../DebtControllerUpdateVerification",
                            type: "post",
                            data: {
                                id: data[0].finance
                            },
                            dataType: "text",
                            success: function (data) {
                                table.reload('consignerTable');
                            }
                        })
                        break;
                    }
                case 'zuofei':
                    if (data.length==0){
                        alert("请选择一行")
                    } else if (data.length>1){
                        alert("只能选中一行")
                    }else {
                        $.ajax({
                            url: "../../DebtControllerUpdateZuoFei",
                            type: "post",
                            data: {
                                id: data[0].finance
                            },
                            dataType: "text",
                            success: function (data) {
                                table.reload('consignerTable');
                            }
                        })
                        break;
                    }
                    break;
            };
        });



    })


</script>